package com.macro.mall.utils;

import com.macro.mall.model.CnRegionInfo;
import com.macro.mall.service.CnRegionInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author super
 * @title: ProvinceUtil
 * @description: TODO
 * @date 2020/11/19 15:24
 */
@Component
public class ProvinceUtil {
    @Autowired
    private CnRegionInfoService cnRegionInfoService;
    private Map<String,String> map = new HashMap<>();

    @PostConstruct
    public void postConstruct() {
        List<CnRegionInfo> groupListById = cnRegionInfoService.findGroupListById(null, "1");
        for(CnRegionInfo a: groupListById) {
            String json = "{\"provCode\":\""+a.getCriCode()+"\",\"provName\":\""+a.getCriName()+"\"}";
            map.put(a.getCriName(),json);
        }
        List<CnRegionInfo> groupListById1 = cnRegionInfoService.findGroupListById(null, "2");
        for(CnRegionInfo b: groupListById1) {
            String json = "{\"cityCode\":\""+b.getCriCode()+"\",\"cityName\":\""+b.getCriName()+"\"}";
            map.put(b.getCriName(),json);
        }
        List<CnRegionInfo> groupListById2 = cnRegionInfoService.findGroupListById(null, "3");
        for(CnRegionInfo c: groupListById2) {
            String json = "{\"countyCode\":\""+c.getCriCode()+"\",\"countyName\":\""+c.getCriName()+"\"}";
            map.put(c.getCriName(),json);
        }
    }
    public String getCodeJson(String name) {
        String s = map.get(name);
        return s;
    }


}
